<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>

<!--  注册模块 -->
    <div class="form-group">
    <label for="username" class="col-sm-2 control-label">用户名</label>
    <div class="col-sm-10">
      <input type="text" required="required" class="form-control" id="username" placeholder="请输入用户名">
    </div>
  </div>
  <div class="form-group">
    <label for="password" class="col-sm-2 control-label">密码</label>
    <div class="col-sm-10">
      <input type="password" required="required" class="form-control" id="password" placeholder="输入6-20个字母、数字、下划线">
    </div>
  </div>
  <div class="form-group">
    <label for="password_2" class="col-sm-2 control-label">重复密码</label>
    <div class="col-sm-10">
      <input type="password" required="required" class="form-control" id="password_2" placeholder="输入6-20个字母、数字、下划线">
    </div>
  </div>
  <div class="form-group">
    <label for="sex" class="col-sm-2 control-label">性别</label>
    <div class="col-sm-10">
      <input type="text" required="required" class="form-control" id="sex" placeholder="请输入性别">
    </div>
  </div>
  <div class="form-group">
    <label for="phone" class="col-sm-2 control-label">联系电话</label>
    <div class="col-sm-10">
      <input type="text" required="required" class="form-control" id="phone" placeholder="请输入联系电话">
    </div>
  </div>
  <div class="form-group">
    <label for="email" class="col-sm-2 control-label">邮箱</label>
    <div class="col-sm-10">
      <input type="email" required="required" class="form-control" id="email" placeholder="请输入邮箱">
    </div>
  </div>

<script type="text/javascript">
$('#reg-form').submit(function(){
	  var password = $('#password').val();
	  var password2 = $('#password_2').val();
	  
	  if (!isPasswd(password)) {
	  		alert('请输入正确的密码');
	  		return false;
	  }
	  
	  if( password != password2 ){
		  alert('两次密码不一样');
		  return false;
	  }
	  
	  var obj = {};
	  obj.username = $('#username').val();
	  obj.password = $('#password').val();
	  obj.sex = $('#sex').val();
	  obj.phone = $('#phone').val();
	  obj.email = $('#email').val();
	  $.post("../api/user/register",obj,function(data){
	  	  console.log(data);
	  	  if (data.code==0) {
	  		alert('注册成功');
	  		window.location.reload();
		  }else{
			  alert(data.data);
		  }
	  });
  return false;
});


function isPasswd(s)    
{    
var patrn=/^(\w){6,20}$/;    
if (!patrn.exec(s)) return false  
return true  
} 
</script>
</body>
</html>